package com.kitty.game.fight.hunqi.passive;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.FieldValuePosConst;
import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.equip.service.EquipService;
import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.game.fight.message.RespAttackSkillLightEffect;
import com.kitty.game.fight.service.FightMessageService;
import com.kitty.game.fight.util.FightMessageUtil;
import com.kitty.game.utils.Const;

import java.util.concurrent.ThreadLocalRandom;

public class RunZeHunQiEffect extends  HunQiEffect{
    @Override
    public short getEffectId() {
        return 0;
    }

    @Override
    public Object trigger(Fight fight, FightObject effector, Object... params) {
        //是否是人物   被攻击方
        if (!effector.isPlayer()) {
            return false;
        }
        if (SpringUtils.getHunQiService().getSpecialSkillId(effector) != Const.HUNQIRUNZE) {
            return Boolean.FALSE;
        }
        EquipService equipService = SpringUtils.getEquipService();
        RoleEquip hunqi = equipService.getRoleEquipByPos(effector.getRole(), Const.TALISMAN);
        int hunQiCoung = getHunQiCount(hunqi);
        int specialSkillLevel = hunqi.getEquipValue(FieldValuePosConst.HUNQI_SKILL_LEVEL);
        int randIndex = ThreadLocalRandom.current().nextInt(10);
        if(specialSkillLevel <= randIndex){
            return false;
        }
        RespAttackSkillLightEffect respAttackSkillLightEffect = new RespAttackSkillLightEffect();
        respAttackSkillLightEffect.setId(effector.getId());
        respAttackSkillLightEffect.setEffectId((short)0);
        respAttackSkillLightEffect.setType(4);//天书4 其他0
        respAttackSkillLightEffect.setName("润泽");
        FightMessageUtil.sendFightPackage(fight,respAttackSkillLightEffect);
        //恢复血量
        FightMessageService fightMessageService = SpringUtils.getFightMessageService();
        FightMessageUtil.sendFightPackage(fight,
                fightMessageService.decreaseLife(effector.getId(), effector.getId(), hunQiCoung, 4098, 10005));
        effector.setCurrLife(effector.getCurrLife() + hunQiCoung);
        FightMessageUtil.sendFightPackage(fight, fightMessageService.updateTargetLife(effector.getId(), effector.getCurrLife()));

        return true;
    }

    @Override
    public int getHunQiCount(RoleEquip hunqi) {
        int specialSkillLevel = hunqi.getEquipValue(FieldValuePosConst.HUNQI_SKILL_LEVEL);
        int life =(int)( getHunQiSkillValue(hunqi.queryLevel())  * 2 * specialSkillLevel /5);
        return life;
    }

    public static void main(String[] args) {
        int a = 1;
        for (int i = 0; i < 20; i++) {
            int randIndex = ThreadLocalRandom.current().nextInt(10);
            if(a <= randIndex){
                System.out.println(randIndex+"---");
            }else{
                System.out.println(randIndex+"+++");
            }
        }
    }
}
